package org.example.demo1.controller;

import org.example.demo1.common.ResponseData;
import org.example.demo1.domain.GoodsInfo;
import org.example.demo1.service.IGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/api/goods")
public class GoodsController {

    @Autowired
    IGoodsService goodsService;

    @RequestMapping("/add")
    public ResponseData<GoodsInfo> addGoods(GoodsInfo goodsInfo) {
        return goodsService.addGoods(goodsInfo);
    }

    @RequestMapping("/update")
    public ResponseData<GoodsInfo> updateGoods(GoodsInfo goodsInfo) {
        return goodsService.updateGoods(goodsInfo);
    }

    @RequestMapping("/delete")
    public ResponseData<GoodsInfo> deleteGoodsByGoodsId(@RequestParam("goodsId") Integer goodsId) {
        return goodsService.deleteGoodsByGoodsId(goodsId);
    }

    @RequestMapping("/search/name")
    public ResponseData<List<GoodsInfo>> searchGoodsByName(@RequestParam("name") String name) {
        return goodsService.searchGoodsByName(name);
    }

    @RequestMapping("/search/code")
    public ResponseData<List<GoodsInfo>> searchGoodsById(@RequestParam("goodsId") Integer goodsId) {
        return goodsService.searchGoodsById(goodsId);
    }

    @RequestMapping("/pageQuery")
    public ResponseData<List<GoodsInfo>> pageQuery(@RequestParam("pageNum") int pageNum,
                                                   @RequestParam("pageSize") int pageSize,
                                                   @RequestParam(value = "classifyId", required = false) String classifyId) {
        return goodsService.pageQuery(pageNum, pageSize, classifyId);
    }
}
